package GUI.MarketingEmployee;

import java.awt.Component;
import java.io.File;
import java.io.IOException;

import javax.swing.JFileChooser;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.filechooser.FileFilter;
import javax.swing.filechooser.FileNameExtensionFilter;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;



public class AddProductPnl extends JPanel {
	public JTextField textFieldName;
	public JTextField textFieldPrice;
	public JTextField textFieldDesc;
	public JTextField textFieldPicture;
	private JLabel lblNewLabel_1;
	private JLabel lblPicture;
	private JButton btnAddPicture;
	private JFileChooser picFile;
	private Component parent;
	public JButton btnAddProduct;
	public JTextField textFieldId;
	
	public AddProductPnl(){
		setLayout(null);
		
		textFieldId = new JTextField();
		textFieldId.setColumns(10);
		textFieldId.setBounds(29, 30, 86, 20);
		add(textFieldId);
		
		textFieldName = new JTextField();
		textFieldName.setBounds(236, 30, 86, 20);
		add(textFieldName);
		textFieldName.setColumns(10);
		
		textFieldPrice = new JTextField();
		textFieldPrice.setBounds(29, 87, 86, 20);
		add(textFieldPrice);
		textFieldPrice.setColumns(10);
		
		textFieldDesc = new JTextField();
		textFieldDesc.setBounds(29, 212, 201, 76);
		add(textFieldDesc);
		textFieldDesc.setColumns(10);
		
		textFieldPicture = new JTextField();
		textFieldPicture.setBounds(29, 143, 276, 20);
		add(textFieldPicture);
		textFieldPicture.setColumns(10);
		
		btnAddProduct = new JButton("Add Product");
		btnAddProduct.setBounds(306, 254, 101, 23);
		add(btnAddProduct);
		
		JLabel lblName = new JLabel("Name:");
		lblName.setBounds(236, 5, 46, 14);
		add(lblName);
		
		JLabel lblType = new JLabel("Price:");
		lblType.setBounds(29, 62, 46, 14);
		add(lblType);
		
		JLabel lblDescription = new JLabel("Description");
		lblDescription.setBounds(29, 187, 70, 14);
		add(lblDescription);
		
		lblPicture = new JLabel("Picture:");
		lblPicture.setBounds(29, 118, 46, 14);
		add(lblPicture);
		
		btnAddPicture = new JButton("Add Picture");
		btnAddPicture.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
				JFileChooser chooser = new JFileChooser();
				FileNameExtensionFilter filter = new FileNameExtensionFilter(
				    "JPG & GIF Images", "jpg", "gif");
				chooser.setFileFilter(filter);
				int returnVal = chooser.showOpenDialog(parent);
				if(returnVal == JFileChooser.APPROVE_OPTION) {
				   System.out.println("You chose to open this file: " +
				        chooser.getSelectedFile().getName());
				   textFieldPicture.setText(chooser.getSelectedFile().getPath());
				}
			}
		});
		btnAddPicture.setBounds(318, 142, 89, 23);
		add(btnAddPicture);
		
		JLabel idLabel = new JLabel("Id:");
		idLabel.setBounds(29, 5, 46, 14);
		add(idLabel);
		
		
			

		
	}
	
	public void addController(ActionListener controller){
		System.out.print("Add Product ->Add controller");
		btnAddProduct.addActionListener(controller);
	}
}
